package com.qf.controller;

import com.qf.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.objenesis.Objenesis;
import org.springframework.objenesis.ObjenesisStd;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

/**
 * @author MI
 * @ClassName GoodsController.java
 * @createTime 2021年12月10日 14:20:00
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Value("${server.port}")
    private String port;

    @RequestMapping("findById/{id}")
    public Goods findById(@PathVariable String id) {
        System.out.println("id=" + id);
        Objenesis objenesis = new ObjenesisStd(true);
        Goods refPerson = objenesis.newInstance(Goods.class);
        System.out.println(refPerson);
        return new Goods("小米" + port, 99.0);
    }

    @PostMapping("save")
    public HashMap save(@RequestBody Goods goods) {

        System.out.println(goods);
        return new HashMap(2) {
            {
                put("code", 200);
                put("msg", "goods save success");
            }
        };
    }

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("a")
    public String a() {
        String object = restTemplate.getForObject("http://cloud-jifen/jifen/b", String.class);
        System.out.println(object);
        return "a" + object;
    }

    @RequestMapping("c")
    public String c() {
        return "c";
    }
}
